package com.advert.presentation.bean;

import com.advert.model.security.UserInfoEntity;
import com.advert.security.AppSecurityManager;
import com.advert.service.security.SecurityService;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import java.io.Serializable;

@Name("aboutMeBean")
@Scope(ScopeType.PAGE)
public class AboutMeBean implements Serializable {
    @In("SecurityManager")
    private AppSecurityManager securityManager;
    @In("SecurityService")
    private SecurityService securityService;

    private UserInfoEntity userInfo;


    // Accessors

    public UserInfoEntity getUserInfo() {
        if (userInfo == null) {
            userInfo = securityService.getUserInfo(securityManager.userId());
        }
        return userInfo;
    }


    // Actions

    public void saveInfo() {
        securityService.updateUserInfo(getUserInfo());
    }
}
